// ============================================================================
//
// Graph framework by Aurelien Moreau aurelien.moreau@gmail.com
// Modified by Pierre CHATEL chatelp@gmail.com
// Distributed under LGPL
// Copyright (C) Aurelien Moreau, 2008, 2009. All rights reserved
//
// ============================================================================

package com.thalesgroup.graphFramework.collections;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MapLists {
	public static <X, Y> MapList<X, Y> newCluster(
			final Iterable<? extends Y> set, final Accessor<X, Y> accessor) {
		return newCluster(set.iterator(), accessor);
	}

	public static <X, Y> MapList<X, Y> newCluster(
			final Iterator<? extends Y> set, final Accessor<X, Y> accessor) {
		if (set == null) {
			return null;
		}
		final AbstractMapList<X, Y> mset = new MapArrayList<X, Y>();
		mset.clusterize(set, accessor);
		return mset;
	}
	
	public static <X,Y> MapList<X,Y> toSingleMapList(Map<X,Y> map) {
		return null;
	}
	
	public static <X,Y> MapList<X,Y> newSingletonCluster(Iterator<? extends Y> ite, Accessor<X,Y> accessor) {
		MapSingletonList<X,Y> result=new MapSingletonList<X,Y>();
		for(;ite.hasNext();) {
			Y value=ite.next();
			X key=accessor.cluster(value);
			result.addSingleton(key, value);
		}
		return result;
	}
	
	private static final class MapSingletonList<X,Y> extends AbstractMapList<X,Y> {

		private static final long	serialVersionUID	= 5835809772222652749L;

		@Override
		public List<Y> createList(int size) {
			return null;
		}

		@Override
		public List<Y> createList() {
			return null;
		}

		@Override
		public List<Y> createList(List<Y> src) {
			return null;
		}
		
		protected void addSingleton(X key, Y value) {
			put(key, Collections.singletonList(value));
		}
	}
}
